package com.ruoyi.combat.service.userlocation.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ruoyi.combat.domain.userlocation.CombatUser;
import com.ruoyi.combat.domain.userlocation.CombatWarn;
import com.ruoyi.combat.mapper.userlocation.CombatUserMapper;
import com.ruoyi.combat.mapper.userlocation.CombatWarnMapper;
import com.ruoyi.combat.service.userlocation.ICombatWarnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 告警信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-30
 */
@Service
public class CombatWarnServiceImpl implements ICombatWarnService {
    @Autowired
    private CombatWarnMapper combatWarnMapper;
    @Autowired
    private CombatUserMapper combatUserMapper;

    /**
     * 查询告警信息
     *
     * @param id 告警信息主键
     * @return 告警信息
     */
    @Override
    public CombatWarn selectCombatWarnById(Long id) {
        return combatWarnMapper.selectCombatWarnById(id);
    }

    /**
     * 查询告警信息列表
     *
     * @param combatWarn 告警信息
     * @return 告警信息
     */
    @Override
    public List<CombatWarn> selectCombatWarnList(CombatWarn combatWarn) {
        /*if(combatWarn!=null&&combatWarn.getUserid()!=null){
            return combatWarnMapper.selectCombatWarnList(combatWarn);
        }else{
            return combatWarnMapper.selectCombatWarnListNew(combatWarn);
        }*/

        List<CombatWarn> combatWarns = combatWarnMapper.selectCombatWarnListNew(combatWarn);
        for (CombatWarn warn : combatWarns){
            CombatUser combatUser = combatUserMapper.selectCombatUserByUserId(warn.getUserid());
            warn.setUseredId(combatUser.getId());
        }
        return combatWarns;

    }

    /**
     * 新增告警信息
     *
     * @param combatWarn 告警信息
     * @return 结果
     */
    @Override
    public int insertCombatWarn(CombatWarn combatWarn) {
        combatWarn.setCreateTime(new Date());
        combatWarn.setWarnState("0");
        return combatWarnMapper.insertCombatWarn(combatWarn);
    }

    /**
     * 修改告警信息
     *
     * @param combatWarn 告警信息
     * @return 结果
     */
    @Override
    public int updateCombatWarn(CombatWarn combatWarn) {
        return combatWarnMapper.updateCombatWarn(combatWarn);
    }

    /**
     * 批量删除告警信息
     *
     * @param ids 需要删除的告警信息主键
     * @return 结果
     */
    @Override
    public int deleteCombatWarnByIds(Long[] ids) {
        return combatWarnMapper.deleteCombatWarnByIds(ids);
    }

    /**
     * 删除告警信息信息
     *
     * @param id 告警信息主键
     * @return 结果
     */
    @Override
    public int deleteCombatWarnById(Long id) {
        return combatWarnMapper.deleteCombatWarnById(id);
    }

    @Override
    public List<Map> getAreaByProvince() {
        return combatWarnMapper.getAreaByProvince();
    }

    @Override
    public List<Map> getPostionsByWarn(){
        return combatWarnMapper.getPostionsByWarn();
    }
}
